package com.example.androideventdistribution.page1

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.androideventdistribution.R


class OuterRecyclerViewAdapter(outerItemList: List<OuterItem>) : RecyclerView.Adapter<OuterRecyclerViewAdapter.ViewHolder>() {
    private val outerItemList: List<OuterItem> = outerItemList

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var innerRecyclerView: InnerRecyclerView = view.findViewById(R.id.innerRecyclerView)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view: View = LayoutInflater.from(parent.context).inflate(R.layout.item_outer, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val outerItem: OuterItem = outerItemList[position]
        // 配置内部 RecyclerView
        val innerAdapter = InnerRecyclerViewAdapter(outerItem.getInnerItems())
        holder.innerRecyclerView.layoutManager = GridLayoutManager(holder.itemView.context, 2)
        holder.innerRecyclerView.adapter = innerAdapter
    }

    override fun getItemCount(): Int {
        return outerItemList.size
    }
}
